package com.zretc.support.dao;

import com.zretc.support.entity.Collection;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;

@Repository
public interface CollectionDao extends JpaRepository<Collection,Integer>, JpaSpecificationExecutor<Collection>,
        CrudRepository<Collection,Integer>, Serializable {

    @Query(value="select * from collection where userId = ?1",nativeQuery = true)
    Page<Collection> getCollectionByPageWithUserId(String userId, Pageable pageable);

    @Query("select c from Collection c inner join Answer a on c.answer.answerId = a.answerId where c.user.userId = ?1 order by c.collectionId desc ")
    @Transactional
    Page<Collection> findCollByUserId(String userId, Pageable pageable);


}
